﻿using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;

namespace DocX_WordDemo
{
    public static class Miscellaneous
    {
        public static void InsertOLEObject(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            Paragraph p = doc.LastSection.AddParagraph();
            DocPicture pic = new DocPicture(doc);
            pic.LoadImage(Image.FromFile("../../Document/Object.png"));
            pic.HorizontalAlignment = ShapeHorizontalAlignment.Center;
            pic.WidthScale = 85f;
            p.AppendOleObject("../../Document/Object.xlsx", pic, OleObjectType.ExcelWorksheet);
            doc.SaveToFile(outputFileName);
        }

        public static void SetViewMode(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            doc.ViewSetup.DocumentViewType = DocumentViewType.WebLayout;
            doc.ViewSetup.ZoomPercent = 150;
            doc.ViewSetup.ZoomType = ZoomType.None;
            doc.SaveToFile(outputFileName);
        }

        public static void PageSetup(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            Section section = doc.LastSection;
            section.PageSetup.Borders.BorderType = BorderStyle.DoubleWave;
            section.PageSetup.Borders.Color = Color.SeaGreen;
            section.PageSetup.Borders.Top.Space = 10;
            section.PageSetup.Borders.Bottom.Space = 10;
            section.PageSetup.Borders.Left.Space = 10;
            section.PageSetup.Borders.Right.Space = 10;
            section.PageSetup.Orientation = PageOrientation.Landscape;
            doc.SaveToFile(outputFileName);
        }

        public static void Encrypt(string fileName, string outpuFileName, string password)
        {
            Document doc = new Document(fileName);
            doc.Encrypt(password);
            doc.SaveToFile(outpuFileName);
        }

        public static void RemoveMacro(string fileName, string outputFileName)
        {
            Document doc = new Document(fileName);
            if (doc.IsContainMacro)
            {
                doc.ClearMacros();
            }
            doc.SaveToFile(outputFileName);
        }

    }
}
